package SpaceIT.pages;
import java.util.ArrayList;

import model.dao.SanPhamDAO;

import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;

import view.util.util;

public class ChiTietSanPham 
{
	@Inject
	private Request request;
	
	@Property
	private util viewHelper = new util();
	
	@Property
	private int i;
	
	@Property
	private ArrayList<String> ttChiTiet;
	
	@Property
	private ArrayList<String> spCungDongSanPham;
	
	public ChiTietSanPham(){
//	{
		String s = request.getParameter("MaSP");
		setTTChiTiet(s);
		getSpCungDongSanPham(this.getDongSP());
	}
	
	public ArrayList<String> getTTChiTiet(){
//	{
		return ttChiTiet;
	}
		
	public void setTTChiTiet(String MaSP){
//	{
		ttChiTiet = SanPhamDAO.ChiTietSanPham(MaSP);
	}

	private void getSpCungDongSanPham(String DongSP) {
//	{
		ArrayList<ArrayList<String>> spcl = SanPhamDAO.SanPhamCungDongSanPham(DongSP);
		spCungDongSanPham = new ArrayList<String>();
		
		for(int i = 0 ; i < spcl.size() ; i = i + 3)
		{
			String s = "";
			String url = "ChiTietSanPham?MaSP=";
			
			for(int j = 0 ; j < 3 && j + i < spcl.size() ; j++ )
			{
				s += "<div class='products_list_content_item'>";
				s += "	<div class='products_list_content_item_pic'>";
				s += "		<a href='" + url + spcl.get(j + i).get(0) + "' title='" + spcl.get(j + i).get(1) +"'>";
				s += "			<img src='" + spcl.get(j + i).get(7) + "' alt='" + spcl.get(j + i).get(1) +" width='120px' height='120px'/>";
				s += "		</a>";
				s += "		<p><br/>" + spcl.get(j + i).get(2) + " VNĐ</p>";
				s += "		<div class='luotxem'> Lượt xem: " + spcl.get(j + i).get(6) + "</div>";
				s += "	</div>";
				s += "	<div class='products_list_content_item_main'>";
				s += "		<div class='products_list_content_item_name'>";
				s += "			<a href='" + url + spcl.get(j + i).get(0) + "' title='" + spcl.get(j + i).get(1) +"'>";
				s +=  				spcl.get(j + i).get(1);
				s += "			</a>";
				s += "		</div>";
				s += "		<div class='products_list_content_item_des'>";
				s += "			<span style='font-size: small; font-family: arial,helvetica,sans-serif;'>";
				s += 				spcl.get(j + i).get(3);	
				s += "			</span>"; 
				s += "			<br/>";
				s += "		</div>";
				s += "		<div class='products_list_content_item_warr'>";
				s += "			<span class='warr_padd' style='padding-left: 20px;'>Bảo hành: " + spcl.get(j + i).get(4) + " Tháng</span>";
				s += "			<span class='warr_padd'> Kho: " + spcl.get(j + i).get(5) + "</span>";
				s += String.format("<input type='image' style='float: right;' src='layout/images/GiaoDien/dathang.gif' MaSP='%s' TenSP='%s' GiaBan='%s' linkHinh='%s' class='btnMua' />",spcl.get(j + i).get(0) , spcl.get(j + i).get(1) , spcl.get(j + i).get(2) , spcl.get(j + i).get(7));
				s += "			<div style='clear: both; margin-bottom: 3px;'></div>";
				s += "		</div>";
				s += "	</div>";
				s += "	<div class='clr products_list_content_bot'></div>";
				s += "</div>";
			}
			spCungDongSanPham.add(s);
		}
	}
	
	public String getMaSP(){
//	{
		return ttChiTiet.get(0);
	}
	public String getTenSP(){
//	{
		return ttChiTiet.get(1);
	}
	public String getGiaBan(){
//	{
		return ttChiTiet.get(2);
	}	

	public String getHienTrang(){
//	{
		return ttChiTiet.get(3);
	}
	
	public String getThoiGianBaoHanh(){
//	{
		return ttChiTiet.get(4);
	}
	
	public String getThongTinKhuyenMai(){
//	{
		return ttChiTiet.get(5);
	}
	
	public String getModel(){
//	{
		return ttChiTiet.get(6);
	}
	
	public String getLoaiManHinh(){
//	{
		return ttChiTiet.get(7);
	}
	public String getKichThuocDiemAnh(){
//	{
		return ttChiTiet.get(8);
	}
	
	public String getCuongDoSang(){
//	{
		return ttChiTiet.get(9);
	}
	
	public String getDoTuongPhan(){
//	{
		return ttChiTiet.get(10);
	}
	
	public String getGocNhin(){
//	{
		return ttChiTiet.get(11);
	}
	
	public String getDoPhanGiai(){
//	{
		return ttChiTiet.get(12);
	}
	
	public String getKhaNangHienThiMau(){
//	{
		return ttChiTiet.get(13);
	}
	
	public String getThoiGianDapUng(){
//	{
		return ttChiTiet.get(14);
	}
	
	public String getCacKieuKetNoiHoTro(){
//	{
		return ttChiTiet.get(15);
	}
	
	public String getHieuDienTheVao(){
//	{
		return ttChiTiet.get(16);
	}
	
	public String getCongSuatTieuThu(){
//	{
		return ttChiTiet.get(17);
	}
	
	public String getTrongLuong(){
//	{
		return ttChiTiet.get(18);
	}
		
	public String getKichThuoc(){
//	{
		return ttChiTiet.get(19);
	}
	
	public String getHinhAnh(){
//	{
		if(ttChiTiet.size() > 12)
			return ttChiTiet.get(20);
		else
			return ttChiTiet.get(6);
	}
	
	public String getSoLuongTon(){
//	{
		if(ttChiTiet.size() > 12)
			return ttChiTiet.get(21);
		else
			return ttChiTiet.get(7);
	}
	
	public String getDongSP(){
//	{
		if(ttChiTiet.size() > 12)
			return ttChiTiet.get(22);
		else
			return ttChiTiet.get(8);
	}
	
	public String getMoTaSanPham(){
//	{
		return ttChiTiet.get(9);
	}

	public boolean isOutPut(){
//	{
		if (i < spCungDongSanPham.size())
			return true;
		return false;
	}
	
	public boolean isManHinh(){
//	{
		if(ttChiTiet.size() > 12)
			return true;
		return false;
	}
}